﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace patchPack
{
	class HashMod
	{
		// 将字符串内容转化为SHA1的degist信息摘要
		public static string CreateMD5Digest(string content)
		{
			MD5 sha1 = new MD5CryptoServiceProvider();
			byte[] contentKey = Encoding.Default.GetBytes(content);
			byte[] encryptContent = sha1.ComputeHash(contentKey);
			string resultStr = "";
			// 这里性能有点差
			foreach (byte test in encryptContent)
			{
				resultStr = resultStr + test.ToString("X2");
			}
			return resultStr.ToLower();
		}

		//// 将字符串内容转化为SHA256的Hmac信息摘要
		//public static string createSHA256Hmac(string content, string EncryptKey)
		//{
		//	byte[] byteKey = Encoding.UTF8.GetBytes(EncryptKey);
		//	byte[] contentKey = Encoding.UTF8.GetBytes(content);

		//	HMAC sha256Hash = new HMACSHA256(byteKey);
		//	byte[] encryptContent = sha256Hash.ComputeHash(contentKey);

		//	string resultStr = "";
		//	// 这里性能有点差
		//	foreach (byte test in encryptContent)
		//	{
		//		resultStr = resultStr + test.ToString("X2");
		//	}
		//	return resultStr.ToLower();
		//}

		//// 将字符串内容转化为SHA512的Hmac信息摘要
		//public static string createSHA512Hmac(string content, string EncryptKey)
		//{
		//	byte[] byteKey = Encoding.UTF8.GetBytes(EncryptKey);
		//	byte[] contentKey = Encoding.UTF8.GetBytes(content);

		//	HMAC sha512Hash = new HMACSHA512(byteKey);
		//	byte[] encryptContent = sha512Hash.ComputeHash(contentKey);

		//	string resultStr = "";
		//	// 这里性能有点差
		//	foreach (byte test in encryptContent)
		//	{
		//		resultStr = resultStr + test.ToString("X2");
		//	}
		//	return resultStr.ToLower();
		//}

		//// 将字符串内容转化为SHA384的degist信息摘要
		//public static string createSHA384Digest(string content)
		//{
		//	SHA384 sha384 = new SHA384CryptoServiceProvider();//建立一個SHA384
		//	byte[] contentKey = Encoding.Default.GetBytes(content);//將字串轉為Byte[]
		//	byte[] encryptContent = sha384.ComputeHash(contentKey);//進行SHA384加密
		//	string resultStr = "";
		//	// 这里性能有点差
		//	foreach (byte test in encryptContent)
		//	{
		//		resultStr = resultStr + test.ToString("X2");
		//	}
		//	return resultStr.ToLower();
		//}

		////将字符串内容转化为SHA1的degist信息摘要
		////public static string createSHA1Digest(string content)
		////{
		////	SHA1 sha1 = new SHA1CryptoServiceProvider();
		////	byte[] contentKey = Encoding.Default.GetBytes(content);
		////	byte[] encryptContent = sha1.ComputeHash(contentKey);
		////	string resultStr = "";
		////	这里性能有点差
		////	foreach (byte test in encryptContent)
		////	{
		////		resultStr = resultStr + test.ToString("X2");
		////	}
		////	return resultStr.ToLower();
		////}

		//public static string createHash(string content)
		//{
		//	string content1 = "common";
		//	string content2 = "json";
		//	string hs1 = createSHA256Hmac(content1, "image/harem/uma.png");
		//	string hs2 = createSHA512Hmac(content2, "!@#5%hK");
		//	string hashStr = createSHA1Digest("#" + hs1 + "$" + content + "<huangshangjixiang>" + hs2 + "*" + createSHA384Digest("test"));
		//	return hashStr;

		//}
	}
}
